package com.health.fragment.focusgroup.maternity;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import com.health.viewscontrols.FWMYDPJActivity;
import com.health.viewscontrols.NovaApplication;
import com.health.viewscontrols.PersonalFileActivity.onFragmentSave;
import com.health.R;
import com.health.adapter.CheckBoxAdapter;
import com.health.adapter.RadioButtonAdapter;
import com.health.db.FDbManager;
import com.health.viewscontrols.focusgroup.MaternityActivity;
import com.health.fragment.NovaFragment;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.tablebean.BD_DD_INFO;
import com.health.tablebean.GRAVIDA_BASEINFO;
import com.health.tablebean.GRAVIDA_TWO2FIVE_FOLLOWUP;
import com.health.tools.GlobalConts;
import com.health.view.spinner.NiceSpinner;
import com.health.widget.EditTextWithDate;
import com.health.widget.MyGridView;
import com.novabluetooth.services.BluetoothConstant;
import com.novabluetooth.views.ExamHistoryActivity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

/**
 * 重点人群-- 孕妇---产前随访4
 * 
 * @author nova
 *
 */
public class Maternity_Cqsf4Fragment extends NovaFragment implements onFragmentSave, OnClickListener {
	private View cqsf2View = null;
	private FDbManager fdbmanger = null;

	// ------------------------------基本信息-----------------------------
	private EditTextWithDate ed_date;
	private EditText ed_zq;// 周期
	private EditText ed_zs;// 主诉

	private EditText ed_weight;// 体重
	private Button btn_choose_weight;// 选择体重

	private EditText ed_gdgd;// 宫底高度
	private EditText ed_fw;// 腹围
	private NiceSpinner nice_spinner_tw;// 胎位

	private EditText ed_txl;// 胎心率
	private NiceSpinner nice_spinner_ndb;// 尿蛋白
	private EditText ed_xy;// 血压
	private Button btn_choose_xy;

	private EditText ed_xhdb;// 血红蛋白
	private Button btn_choose_xhdb;//
	private EditText ed_qtfzjc;// 其他辅助检查

	private MyGridView gd_ztpg;// 总体评估
	private MyGridView gd_bjzd;// 保健指导
	// private MyGridView gd_zz;// 转诊
	private EditText ed_jg_ys;// 机构及科室

	private EditTextWithDate ed_xcsfsj;// 下次随访时间
	private NiceSpinner ed_sfysqm;// 随访医生签名

	private RadioGroup rd_zz;// 是否转诊
	private RadioButton rb_w;
	private RadioButton rb_y;
	// ----------------------------------------------------------------------
	// private RadioButtonAdapter adapter_zz= null;
	private RadioButtonAdapter adapter_fl = null;

	private CheckBoxAdapter adapter_bjzd = null;

	private String str_flId = "";
	private String str_flContent = "";
	private String str_zzId = "";
	private String str_zhidaoId = "";
	private String str_zhidaoContent = "";

	private List<BD_DD_INFO> tw_list = new ArrayList<BD_DD_INFO>();
	private List<BD_DD_INFO> ndb_list = new ArrayList<BD_DD_INFO>();
	private TextView tv_flag;
	private TextView tv_name;
	public ARCHIVE_BASEINFO userInfo;
	private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	private EditText ed_zzyy;
	private int from_followup = -1;
	private TextView tv_cc;//产次
	private GRAVIDA_BASEINFO gravida_baseInfo= NovaApplication.gravida_baseInfo;// 孕妇信息

	@Override
	public View findViews(LayoutInflater inflater) {
		fdbmanger = NovaApplication.fdbmanger;
		userInfo = NovaApplication.getUserInfo();
		cqsf2View = inflater.inflate(R.layout.maternity_cqsf2, null);
		initViews(cqsf2View);
		GlobalConts.setMaxLength(20, ed_xy);// 血压
		GlobalConts.setMaxLength(10, ed_xhdb, // 血红蛋白
				ed_jg_ys);// 机构
		GlobalConts.setMaxLength(50, ed_qtfzjc);// 其他辅助检查
		return cqsf2View;
	}

	/**
	 * 初始化布局
	 * 
	 * @param v
	 * @author 王婷婷
	 * @date 2015年12月21日 上午11:10:55
	 */
	private void initViews(View v) {
		tv_flag = (TextView) v.findViewById(R.id.tv_flag);
		tv_flag.setText("第4次产前随访");
		tv_name = (TextView) v.findViewById(R.id.tv_name);
		tv_name.setText("姓名：" + userInfo.getCUSTOMERNAME());
		ed_date = (EditTextWithDate) v.findViewById(R.id.ed_date);
		ed_date.setBefore(true);
		ed_zq = (EditText) v.findViewById(R.id.ed_zq);

		ed_weight = (EditText) v.findViewById(R.id.ed_weight);
		btn_choose_weight = (Button) v.findViewById(R.id.btn_choose_weight);
		ed_xy = (EditText) v.findViewById(R.id.ed_xy);
		btn_choose_xy = (Button) v.findViewById(R.id.btn_choose_xy);
		ed_zzyy = (EditText) v.findViewById(R.id.ed_zzyy);

		ed_zs = (EditText) v.findViewById(R.id.ed_zs);

		ed_gdgd = (EditText) v.findViewById(R.id.ed_gdgd);
		ed_fw = (EditText) v.findViewById(R.id.ed_fw);

		ed_txl = (EditText) v.findViewById(R.id.ed_txl);

		ed_xhdb = (EditText) v.findViewById(R.id.ed_xhdb);
		btn_choose_xhdb = (Button) v.findViewById(R.id.btn_choose_xhdb);
		ed_qtfzjc = (EditText) v.findViewById(R.id.ed_qtfzjc);

		gd_ztpg = (MyGridView) v.findViewById(R.id.gd_ztpg);
		gd_bjzd = (MyGridView) v.findViewById(R.id.gd_bjzd);
		// gd_zz = (MyGridView) v.findViewById(R.id.gd_zz);
		ed_jg_ys = (EditText) v.findViewById(R.id.ed_jg_ys);

		ed_xcsfsj = (EditTextWithDate) v.findViewById(R.id.ed_xcsfsj);
		ed_sfysqm = (NiceSpinner) v.findViewById(R.id.ed_sfysqm);

		nice_spinner_ndb = (NiceSpinner) v.findViewById(R.id.nice_spinner_ndb);
		nice_spinner_tw = (NiceSpinner) v.findViewById(R.id.nice_spinner_tw);

		rd_zz = (RadioGroup) v.findViewById(R.id.rd_zz);
		rb_w = (RadioButton) v.findViewById(R.id.rb_w);
		rb_y = (RadioButton) v.findViewById(R.id.rb_y);
		tv_cc = (TextView) v.findViewById(R.id.tv_cc);
		ed_zzyy.setEnabled(false);
		ed_jg_ys.setEnabled(false);
	}

	@Override
	public void setupView(View view) {
		// TODO Auto-generated method stub

	}

	@Override
	public void addListener() {
		rd_zz.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				if (checkedId == R.id.rb_w) {
					str_zzId = "DM01-11_1";
					ed_zzyy.setText("");
					ed_zzyy.setEnabled(false);
					ed_jg_ys.setText("");
					ed_jg_ys.setEnabled(false);

				} else if (checkedId == R.id.rb_y) {
					str_zzId = "DM01-11_2";
					ed_zzyy.setEnabled(true);
					ed_jg_ys.setEnabled(true);
				} else {
					str_zzId = "";
				}

			}
		});
		btn_choose_xy.setOnClickListener(this);
		btn_choose_weight.setOnClickListener(this);
		btn_choose_xhdb.setOnClickListener(this);
	}

	@Override
	public void setData() {
		List<GRAVIDA_BASEINFO> gradicas = fdbmanger.findAllByWhere(GRAVIDA_BASEINFO.class,
				"IDCARD = '" + userInfo.getIDCARD()+"'");
		if (gradicas.size() > 0) {
			gravida_baseInfo = gradicas.get(0);
		}
		checkFetusTime();
		GlobalConts.doctorList(ed_sfysqm);
		// bindDdata("转诊", "PARENTID='DM01-11'");
		bindDdata("总体评估", "PARENTID='DM01-40'");
		bindDdata("保健指导", "PARENTID='DM06-03'");
		bindSpinner("胎位", "PARENTID='DM06-04'");
		bindSpinner("尿蛋白", "PARENTID='DM100-38'");
		setData_followUP();

		setDateCheck();
	}

	/**
	 * 检查是否已经填写孕次
	 */
	private void checkFetusTime() {
		List<GRAVIDA_BASEINFO> gradicas = fdbmanger.findAllByWhere(GRAVIDA_BASEINFO.class,
				"IDCARD = '" + userInfo.getIDCARD()+"'");
		if (gradicas.size() > 0) {
			if (TextUtils.isEmpty(gradicas.get(0).getFetusTimes())){
				((MaternityActivity) getActivity()).showTextDialog("请先完善基本信息中的产次信息再进行随访操作");
				return;
			}else{
				List<BD_DD_INFO> bd_cc = getBDById(gravida_baseInfo.getFetusTimes());
				if (bd_cc != null) {
					tv_cc.setText(bd_cc.get(0).getDATAINFO());
				}

			}
		}else{
			((MaternityActivity) getActivity()).showTextDialog("请先完善基本信息再进行随访操作");
			return;
		}
	}

	/**
	 * 通过id查询返回的数据
	 *
	 * @param str_id
	 * @return
	 * @author 王婷婷
	 * @date 2015年12月15日 下午6:38:52
	 */
	private List<BD_DD_INFO> getBDById(String str_id) {
		if (str_id != null) {

			List<BD_DD_INFO> bds = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class, "ID='" + str_id + "'");
			if (bds.size() > 0) {

				return bds;
			} else {
				return null;
			}
		} else {
			return null;
		}

	}

	/**
	 * 设置验证展示
	 * 
	 * @author 王婷婷
	 * @date 2016年2月3日 上午10:49:40
	 */
	private void setDateCheck() {
		// 设置时间
		GlobalConts.checkDateAfter(ed_date, ed_xcsfsj);
		// 孕周
		GlobalConts.checkNumOrange(getActivity(), ed_zq, 49, 0);
		// 体重
		GlobalConts.keep2decimal(ed_weight);
		GlobalConts.checkNum(getActivity(), ed_weight, 100, 1, 999);
		// 宫底高度
		GlobalConts.keep2decimal(ed_gdgd);
		GlobalConts.checkNumOrange(getActivity(), ed_gdgd, 99, 0);
		// 腹围
		GlobalConts.keep2decimal(ed_fw);
		GlobalConts.checkNumOrange(getActivity(), ed_fw, 199, 0);
		// 胎心率
		GlobalConts.checkNumOrange(getActivity(), ed_txl, 199, 1);
	}

	@Override
	public void save() {
		checkFetusTime();
		String str_yz = ed_zq.getText().toString();
		if (TextUtils.isEmpty(str_yz)) {
			ed_zq.setBackgroundColor(Color.YELLOW);
			((MaternityActivity) getActivity()).showTextDialog("请填写孕周");
			return;
		} else {
			if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), ed_zq, 49, 0)) {
				ed_zq.setBackgroundColor(Color.YELLOW);
				((MaternityActivity) getActivity()).showTextDialog("孕周数据不合理，保存失败");
				return;
			}
			ed_zq.setBackgroundColor(Color.WHITE);
		}
		String str_zs =ed_zs.getText().toString();
		if (TextUtils.isEmpty(str_zs)) {
			ed_zs.setBackgroundColor(Color.YELLOW);
			((MaternityActivity) getActivity()).showTextDialog("请填写主诉");
			return;
		} else {
			ed_zs.setBackgroundColor(Color.WHITE);
		}
		
		if (!GlobalConts.getCheckNumBoolean(getActivity(), ed_weight, 100, 1, 999)) {
			((MaternityActivity) getActivity()).showTextDialog("体重数据不合理，保存失败");
			return;
		}
		if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), ed_gdgd, 99, 0)) {
			((MaternityActivity) getActivity()).showTextDialog("宫底高度数据不合理，保存失败");
			return;
		}
		if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), ed_fw, 199, 0)) {
			((MaternityActivity) getActivity()).showTextDialog("腹围数据不合理，保存失败");
			return;
		}
		if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), ed_txl, 199, 1)) {
			((MaternityActivity) getActivity()).showTextDialog("胎心率数据不合理，保存失败");
			return;
		}
		//下次随访时间
		String str_xcsfsj = ed_xcsfsj.getText().toString();
		if (TextUtils.isEmpty(str_xcsfsj)) {
			ed_xcsfsj.setBackgroundColor(Color.YELLOW);
			((MaternityActivity) getActivity()).showTextDialog("请选择下次随访时间");
			return;
		} else {
			ed_xcsfsj.setBackgroundColor(Color.WHITE);
		}
		getRadioButtonCheckedData();
		getCheckBoxedData();
		saveData_followup();
	}

	/**
	 * 绑定数据值
	 * 
	 * @param str_where
	 * @param flag
	 * @author 王婷婷
	 * @date 2015年12月17日 上午10:30:30
	 */
	private void bindDdata(String flag, String str_where) {
		List<BD_DD_INFO> listZZs = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
				str_where + " order by cast(SORT as int) asc");

		// if (flag.equals("转诊")) {
		// adapter_zz= new RadioButtonAdapter(listZZs,getActivity());
		// gd_zz.setAdapter(adapter_zz);
		// }else
		if (flag.equals("总体评估")) {
			adapter_fl = new RadioButtonAdapter(listZZs, getActivity());
			adapter_fl.setOtherMaxLength(50);
			gd_ztpg.setAdapter(adapter_fl);
		} else if (flag.equals("保健指导")) {
			List<BD_DD_INFO> listZZs_new = new ArrayList<BD_DD_INFO>();
			int size = listZZs.size();
			if (size > 0) {
				for (int i = 0; i < size; i++) {

					// 个人卫生 DM06-03_1 、 心理 DM06-03_2 、膳食DM06-03_3、运动
					// DM06-03_6、其他 DM06-03_99 、分娩准备DM06-03_8
					if (listZZs.get(i).getID().equals("DM06-03_15") || listZZs.get(i).getID().equals("DM06-03_2")
							|| listZZs.get(i).getID().equals("DM06-03_14") || listZZs.get(i).getID().equals("DM06-03_6")
							|| listZZs.get(i).getID().equals("DM06-03_7") || listZZs.get(i).getID().equals("DM06-03_9")
							|| listZZs.get(i).getID().equals("DM06-03_99")
							|| listZZs.get(i).getID().equals("DM06-03_8")) {
						listZZs_new.add(listZZs.get(i));
					}
				}
			}
			Collections.swap(listZZs_new,1,2);
			adapter_bjzd = new CheckBoxAdapter(getActivity(), listZZs_new);
			adapter_bjzd.setOtherMaxLength(50);
			gd_bjzd.setAdapter(adapter_bjzd);
		}
	}

	/**
	 * 设置下拉
	 * 
	 * @param flagName
	 * @param strSql
	 * @author 王婷婷
	 * @date 2015年12月24日 上午9:19:28
	 */

	private void bindSpinner(String flagName, String strSql) {
		List<BD_DD_INFO> sList = new ArrayList<BD_DD_INFO>();
		BD_DD_INFO bd = new BD_DD_INFO();
		bd.setDATAINFO("请选择");
		bd.setID("");
		sList.add(bd);
		List<BD_DD_INFO> sList1 = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
				strSql + " order by cast(SORT as int) asc");
		sList.addAll(sList1);
		if (flagName.equals("胎位")) {
			tw_list = sList;
			nice_spinner_tw.attachDataSource(tw_list);

		} else if (flagName.equals("尿蛋白")) {
			ndb_list = sList;
			nice_spinner_ndb.attachDataSource(ndb_list);

		}

	}

	/**
	 * 获取转诊的信息
	 * 
	 * @author 王婷婷
	 * @date 2015年12月16日 下午3:10:48
	 */
	private void getRadioButtonCheckedData() {
		str_flId = adapter_fl.getChecked();
		str_flContent = adapter_fl.getCheckedOther();
		// str_zzId = adapter_zz.getChecked();

	}

	/**
	 * 获取 被选中的checkbox
	 * 
	 * @author 王婷婷
	 * @date 2015年12月19日 上午11:34:30
	 */
	private void getCheckBoxedData() {
		str_zhidaoId = adapter_bjzd.getCheckedIdsStr();
		str_zhidaoContent = adapter_bjzd.getOther();

	}

	/**
	 * 保存数据
	 * 
	 * @author 王婷婷
	 * @date 2015年12月17日 上午11:13:39
	 */
	private void saveData_followup() {

		GRAVIDA_TWO2FIVE_FOLLOWUP ques = new GRAVIDA_TWO2FIVE_FOLLOWUP();

		ques.setIDCARD(userInfo.getIDCARD());
		ques.setARCHIVEID("");// 设置档案编号
		ques.setABDOMINALCIRUMFERENCE(ed_fw.getText().toString());
		ques.setUTERUSLOWHEIGHT(ed_gdgd.getText().toString());
		ques.setFHR(ed_txl.getText().toString());
		String str_xy = ed_xy.getText().toString();
		if (!TextUtils.isEmpty(str_xy)) {
			if (str_xy.contains("/")) {
				if (!TextUtils.isEmpty(str_xy.split("/")[0])) {
					ques.setHBLOODPRESSURE(str_xy.split("/")[0]);// 收缩压
					ques.setLBLOODPRESSURE(str_xy.split("/")[1]);// 舒张压
				} else {
					ques.setHBLOODPRESSURE("");// 收缩压
					ques.setLBLOODPRESSURE("");// 舒张压
				}
			} else {
				ques.setHBLOODPRESSURE("");// 收缩压
				ques.setLBLOODPRESSURE("");// 舒张压
			}
		} else {
			ques.setHBLOODPRESSURE("");// 收缩压
			ques.setLBLOODPRESSURE("");// 舒张压
		}
		ques.setHB(ed_xhdb.getText().toString());

		ques.setASSISTANTEXAM(ed_qtfzjc.getText().toString());
		ques.setCLASSIFICATION(str_flId);
		ques.setCLASSIFICATION_EX(str_flContent);
		ques.setADVISING(str_zhidaoId);
		ques.setADVISINGOTHER(str_zhidaoContent);

		if (rb_w.isChecked()) {
			str_zzId = "DM01-11_1";
		} else if (rb_y.isChecked()) {
			str_zzId = "DM01-11_2";
		} else {
			str_zzId = "";
		}

		ques.setREFERRAL(str_zzId);
		ques.setREFERRALREASON(ed_zzyy.getText().toString());
		ques.setREFERRALORG(ed_jg_ys.getText().toString());

		String str_ed_time1_start = ed_date.getText().toString();
		if (!TextUtils.isEmpty(str_ed_time1_start)) {
			try {
				ques.setFOLLOWUP_DATE((Date) dateFormat.parse(str_ed_time1_start));
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}

		String str_ed_time_next = ed_xcsfsj.getText().toString();
		if (!TextUtils.isEmpty(str_ed_time_next)) {
			try {
				ques.setNEXTFOLLOWUP_DATE((Date) dateFormat.parse(str_ed_time_next));
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		ques.setFOLLOWUPDOCTOR(NovaApplication.getDoctorList().get(ed_sfysqm.getSelectedIndex()).getUSER_ID());
		ques.setIS_DEL("N");
		ques.setIS_UPDATE("Y");

		// if(!ndb_list.get(nice_spinner_ndb.getSelectedIndex()).getID().equals("-1")){
		// ques.setPRO(ndb_list.get(nice_spinner_ndb.getSelectedIndex()).getID());//尿蛋白
		// }
		ques.setPRO(ndb_list.get(nice_spinner_ndb.getSelectedIndex()).getID());// 尿蛋白

		ques.setPREGANCYWEEKS(ed_zq.getText().toString());

		ques.setCHIEFCOMPLAINT(ed_zs.getText().toString());

		ques.setWEIGHT(ed_weight.getText().toString());

		// if(!tw_list.get(nice_spinner_tw.getSelectedIndex()).getID().equals("-1")){
		// ques.setFETUSPOSITION(tw_list.get(nice_spinner_tw.getSelectedIndex()).getID());
		// }
		ques.setFETUSPOSITION(tw_list.get(nice_spinner_tw.getSelectedIndex()).getID());
		ques.setLAST_UPDATE_DATE(new Date());
		ques.setLAST_UPDATE_BY(NovaApplication.getDoctorList().get(ed_sfysqm.getSelectedIndex()).getUSER_ID());
		if (from_followup == 1) {
			ques.setUPDATEORG(userInfo.getCREATEORG());
			ques.setMODIFIED(NovaApplication.getDoctorList().get(ed_sfysqm.getSelectedIndex()).getUSER_ID());
			fdbmanger.updata(ques, "IDCARD='" + userInfo.getIDCARD() + "'  and TIMES=4");
		} else {
			ques.setTIMES("4");
			ques.setCREATED_DATE(new Date());
			ques.setCREATEORG(userInfo.getCREATEORG());
			ques.setCREATER(userInfo.getCREATER());
			ques.setCREATED_BY(userInfo.getCREATED_BY());
			fdbmanger.save(ques);
			from_followup = 1;
		}
//		((MaternityActivity) getActivity()).showTextDialog("保存成功");
		if (GlobalConts.TYPE_JTYS.equals(NovaApplication.getType()) ) {
			new AlertDialog.Builder(getActivity()).setTitle("保存成功").setMessage("进行满意度评价")
					.setPositiveButton("确定", new DialogInterface.OnClickListener() {

						@Override
						public void onClick(DialogInterface dialog, int which) {
							Intent intent = new Intent(getContext(), FWMYDPJActivity.class);
							intent.putExtra("type", "03");
							intent.putExtra("szfs","");
							startActivity(intent);
						}
					}).show();
		} else if (GlobalConts.TYPE_GJJBGGWS.equals(NovaApplication.getType())) {
			((MaternityActivity) getActivity()).showTextDialog("保存成功");
		}

	}

	/**
	 * 设置 显示followup
	 * 
	 * @author 王婷婷
	 * @date 2015年12月24日 下午2:25:11
	 */
	private void setData_followUP() {
		List<GRAVIDA_TWO2FIVE_FOLLOWUP> queses = fdbmanger.findAllByWhere(GRAVIDA_TWO2FIVE_FOLLOWUP.class,
				"IDCARD='" + userInfo.getIDCARD() + "' and TIMES=4");
		int size = queses.size();
		if (size > 0) {
			from_followup = 1;

			GRAVIDA_TWO2FIVE_FOLLOWUP ques1 = queses.get(0);

			if (ques1.getFOLLOWUP_DATE() != null) {
				try {
					ed_date.setText(dateFormat.format(ques1.getFOLLOWUP_DATE()));
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			if (ques1.getNEXTFOLLOWUP_DATE() != null) {
				try {
					ed_xcsfsj.setText(dateFormat.format(ques1.getNEXTFOLLOWUP_DATE()));
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

			ed_fw.setText(ques1.getABDOMINALCIRUMFERENCE());

			ed_gdgd.setText(ques1.getUTERUSLOWHEIGHT());
			ed_txl.setText(ques1.getFHR());

			String sys_ss = ques1.getHBLOODPRESSURE();

			if (!TextUtils.isEmpty(sys_ss)) {
				String sys_sz = ques1.getLBLOODPRESSURE();
				String str_sy = sys_ss + "/" + sys_sz;
				ed_xy.setText(str_sy);
			}

			ed_xhdb.setText(ques1.getHB());

			ed_qtfzjc.setText(ques1.getASSISTANTEXAM());

			str_flId = ques1.getCLASSIFICATION();
			str_flContent = ques1.getCLASSIFICATION_EX();
			adapter_fl.setChecked(str_flId, str_flContent);

			str_zhidaoId = ques1.getADVISING();
			str_zhidaoContent = ques1.getADVISINGOTHER();
			adapter_bjzd.setChecked(str_zhidaoId);
			adapter_bjzd.setOther(str_zhidaoContent);

			str_zzId = ques1.getREFERRAL();

			if (!TextUtils.isEmpty(str_zzId)) {
				if (str_zzId.equals("DM01-11_1")) {
					rb_w.setChecked(true);
				} else if (str_zzId.equals("DM01-11_2")) {
					rb_y.setChecked(true);
				}
			}

			// adapter_zz.setChecked(str_zzId);

			ed_zzyy.setText(ques1.getREFERRALREASON());
			ed_jg_ys.setText(ques1.getREFERRALORG());

			for (int i = 0; i < NovaApplication.getDoctorList().size(); i++) {
				if (ques1.getFOLLOWUPDOCTOR().equals(NovaApplication.getDoctorList().get(i).getUSER_ID())) {
					ed_sfysqm.setSelectedIndex(i);
				}

			}

			nice_spinner_ndb.setSelectedIndex(getListIndex(ques1.getPRO(), ndb_list));

			ed_zq.setText(ques1.getPREGANCYWEEKS());

			ed_zs.setText(ques1.getCHIEFCOMPLAINT());
			ed_weight.setText(ques1.getWEIGHT());
			nice_spinner_tw.setSelectedIndex(getListIndex(ques1.getFETUSPOSITION(), tw_list));

		} else {
			from_followup = 0;
			ed_date.setText(dateFormat.format(new Date()));
			for (int i = 0; i < NovaApplication.getDoctorList().size(); i++) {
				if (userInfo.getCREATED_BY().equals(NovaApplication.getDoctorList().get(i).getUSER_ID())) {
					ed_sfysqm.setSelectedIndex(i);
				}

			}
		}
	}

	private int getListIndex(String str, List<BD_DD_INFO> bds) {
		if (str != null && !str.equals("")) {

			for (int i = 0; i < bds.size(); i++) {
				if (str.equals(bds.get(i).getID())) {
					return i;
				}
			}
		}
		return 0;
	}

	@Override
	public void onClick(View v) {
		Intent intent = new Intent(getActivity(), ExamHistoryActivity.class);
		int id = v.getId();
		if (id == R.id.btn_choose_xy) {
			intent.putExtra("flag", BluetoothConstant.XUEYA_TYPENAME);
			getActivity().startActivityForResult(intent, GlobalConts.RequestXueya);
		} else if (id == R.id.btn_choose_weight) {
			intent.putExtra("flag", BluetoothConstant.TIZHONG_TYPENAME);
			getActivity().startActivityForResult(intent, GlobalConts.RequestTizhong);
		} else if (id == R.id.btn_choose_xhdb) {
			intent.putExtra("flag", "血红蛋白");
			getActivity().startActivityForResult(intent, GlobalConts.RequestXueHongDanbai);
		} else {
		}

	}

	@Override
	public void setTizhong(String value) {
		ed_weight.setText(value);
	}

	@Override
	public void setXueya(String gaoya, String diya, String mailv) {
		if (!TextUtils.isEmpty(gaoya) && !TextUtils.isEmpty(diya)) {
			ed_xy.setText(gaoya + "/" + diya);
		}
	}

	@Override
	public void setXueHongDanBai(String xhdb) {
		if (!TextUtils.isEmpty(xhdb)) {
			ed_xhdb.setText(String.valueOf((int) (Double.parseDouble(xhdb) * 10)));
		}
	}
}
